home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 March: Reference Library / Dev.CD Mar 96 RL / Dev.CD Mar 96 RL.toast / Technical Documentation / develop / Preliminary Articles / Timing Code / Src / MicrosecondTrapTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-17  |  2.3 KB  |  115 lines  |  [TEXT/KAHL]

  1. /*                                MicrosecondTrapTest.c                                */
  2. /*
  3.  * MicrosecondTrapTest.c
  4.  * Copyright © 1994 Apple Computer Inc.
  5.  * This is a test of the Microsecond trap available on recent systems.
  6.  * All it does is time a single mouse-click.
  7.  */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #ifdef THINK_C
  12. #include <console.h>
  13. #endif
  14. #include "MicrosecondTrap.h"
  15. #include "MicrosecondTrapTest.h"
  16.  
  17. #ifndef THINK_C                /* MPW includes            */
  18. #include <Errors.h>
  19. #include <Script.h>
  20. #include <Types.h>
  21. #include <Files.h>
  22. #include <Resources.h>
  23. #include <QuickDraw.h>
  24. #include <Fonts.h>
  25. #include <Events.h>
  26. #include <Windows.h>
  27. #include <ToolUtils.h>
  28. #include <Memory.h>
  29. #include <Menus.h>
  30. #include <Lists.h>
  31. #include <Printing.h>
  32. #include <Dialogs.h>
  33. #include <StandardFile.h>
  34. #endif
  35.  
  36. #ifndef FALSE
  37. #define FALSE            0
  38. #define TRUE            1
  39. #endif
  40.  
  41. #ifdef __powerc
  42. QDGlobals                qd;
  43. #endif
  44. EventRecord                gEventRecord;
  45.  
  46. void                        ErrorExit(
  47.         OSErr                    errorStatus,
  48.         ConstStr255Param        errorMsg
  49.     );
  50.  
  51. void
  52. main(
  53. #ifdef THINK_C
  54.         int                        argc,
  55.         char                    **argv
  56. #endif
  57.     )
  58. {
  59.         UnsignedWide            start;
  60.         UnsignedWide            end;
  61.         UnsignedWide            elapsed;
  62.         double                    elapsedDouble;
  63.         Str255                    work;
  64.         short                    i;
  65.         DialogPtr                helloDialog;
  66.         
  67.         MaxApplZone();        
  68.         InitGraf(&qd.thePort);
  69.         InitFonts();
  70.         InitWindows();
  71.         InitMenus();
  72.         TEInit();
  73.         InitDialogs(0);
  74.         for (i = 0; i < 3; i++)
  75.             EventAvail(everyEvent, &gEventRecord);
  76.         /* */
  77.         if (MicrosecondTrapPresent() == FALSE)
  78.             ErrorExit(unimpErr, "\pMicrosecond Trap is not supported");
  79.         helloDialog = GetNewDialog(DLOG_Hello, NULL, (WindowPtr) -1);
  80.         if (helloDialog == NULL)
  81.             ErrorExit(resNotFound, "\pMissing dialog resource");
  82.         DrawDialog(helloDialog);
  83.         InitCursor();
  84.         while (Button() == FALSE)
  85.             ;
  86.         Microseconds(&start);
  87.         while (Button())
  88.             ;
  89.         Microseconds(&end);
  90.         DisposeDialog(helloDialog);
  91.         MicrosecondDelta(&start, &end, &elapsed);
  92.         elapsedDouble = MicrosecondToDouble(&elapsed) / 1000000.0;
  93.         sprintf((char *) &work[1], "%0.6lf", elapsedDouble);
  94.         work[0] = strlen((char *) &work[1]);
  95.         ParamText(work, "\p", "\p", "\p");
  96.         NoteAlert(DLOG_Goodbye, NULL);
  97.         ExitToShell();
  98. }
  99.  
  100. void
  101. ErrorExit(
  102.         OSErr                    errorStatus,
  103.         ConstStr255Param        errorMsg
  104.     )
  105. {
  106.         Str255                    work;
  107.         
  108.         NumToString(errorStatus, work);
  109.         ParamText(work, errorMsg, "\p", "\p");
  110.         InitCursor();
  111.         StopAlert(ALRT_Error, NULL);
  112.         ExitToShell();
  113. }
  114.  
  115.